New Features: postal code, private IP override, file logging, hot-reload of mmd Database, Version Upgrades: Go (1.25) , Traefik, semantic, Fixes: Private IP Lookups, missing DB... - #13
Open
P3RF3CTION wants to merge 1 commit into
Conversation
X-GeoIP2-PostalCode header — postal/ZIP code is now populated from GeoLite2-City.mmdb and forwarded as a request header; always XX when using the Country database X-GeoIP2-PrivateIP header — set to true when the client IP is private, loopback, or link-local and no database lookup was performed Private IP override — new config fields privateIPCountry, privateIPRegion, privateIPCity, and privateIPPostalCode allow operator-defined location values to be returned for private/LAN IPs instead of triggering a (failing) database lookup Per-request file logging — new logFilePath config field writes one structured line per request to a separate log file; format: <RFC3339> ip=<ip> country=<cc> region=<rc> city=<city> postal=<zip> private=<bool> Database hot-reload — new dbRefreshInterval config field (in seconds) enables periodic checks for .mmdb file changes on disk; the new reader is swapped in atomically under a sync.RWMutex without restarting Traefik Reverse-proxy awareness — new preferXForwardedForHeader config field uses the first IP from X-Forwarded-For instead of RemoteAddr (e.g. when running behind Cloudflare) Panic-safe DB loading — panics from the mmdb parser (corrupt or truncated files) are caught via recover() and returned as regular errors; the middleware continues to serve requests with Unknown values Bug Fixes Private IPs previously caused spurious lookup errors in the Traefik log; they are now short-circuited before the database is consulted X-GeoIP2-IPAddress was incorrectly set to XX when the database was unavailable; it now always reflects the resolved client IP regardless of lookup outcome isPrivateIP now covers loopback (127.x, ::1) and link-local (169.254.x, fe80::) in addition to RFC 1918 ranges Global lookup variable replaced by a per-instance field protected by sync.RWMutex — multiple middleware instances no longer share state Internal / Chore README.md — corrected header name X-GeoIP2-IsPrivate → X-GeoIP2-PrivateIP (3 occurrences); was inconsistent with the actual header constant in code Dockerfile — base image updated from traefik:2.4.9 to traefik:v3.3; outdated GiGInnovationLabs references in comments updated to traefik-plugins .traefik.yml — testData extended with all new config fields: privateIPCountry, privateIPRegion, privateIPCity, privateIPPostalCode, dbRefreshInterval, logFilePath package.json — semantic-release bumped from ^20.1.0 to ^24.0.0; @commitlint/config-conventional bumped from ^17.4.0 to ^19.0.0; @semantic-release/github ^11.0.0 added as explicit dependency (was referenced in .releaserc.yaml but missing from package.json) package-lock.json — removed; will be regenerated by CI on next run .golangci.yaml — removed duplicate scopelint and ifshort entries; added mnd alongside deprecated gomnd (renamed in golangci-lint v1.56); removed deprecated empty skip-files and skip-dirs directives Go version updated to 1.25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
X-GeoIP2-PostalCodeheader (City DB only)X-GeoIP2-PrivateIPheader — flags private/LAN/loopback IPsprivateIPCountry/privateIPRegion/privateIPCity/privateIPPostalCode— private IPs skip the DB entirely and return operator-defined valueslogFilePathconfig field — structured per-request log filedbRefreshIntervalconfig field — hot-reload of.mmdbwithout Traefik restartpreferXForwardedForHeaderconfig field — useX-Forwarded-Forwhen behind a proxy.mmdbfiles no longer crash the middlewaresync.RWMutexlookup — multiple middleware instances no longer share stateX-GeoIP2-IPAddressalways reflects the resolved client IP, even when the DB is unavailabletraefik:2.4.9→traefik:v3.3go 1.19→go 1.25semantic-release^20→^24,@commitlint/config-conventional^17→^19.golangci.yaml— removed duplicate linter entries, replaced deprecatedgomndwithmndNew Configuration Options
Full Details see the README.md
preferXForwardedForHeaderboolfalseX-Forwarded-Forinstead ofRemoteAddrprivateIPCountrystringXXprivateIPRegionstringXXprivateIPCitystringXXprivateIPPostalCodestringXXdbRefreshIntervalint0.mmdbfile change checks;0disableslogFilePathstringNew Response Headers
X-GeoIP2-PostalCodeXXotherwiseX-GeoIP2-PrivateIPtruewhen IP is private/LAN/loopback and DB was not consultedTest Plan
GeoLite2-City.mmdb)XXfor region/city/postal (GeoLite2-Country.mmdb)10.x,192.168.x,127.x,::1,169.254.x) setsX-GeoIP2-PrivateIP: truepreferXForwardedForHeaderuses first entry ofX-Forwarded-ForlogFilePathcreates file and writes one structured line per requestdbRefreshIntervalreloads DB after file is replaced on disk without restart.mmdbreturnsXXfor all geo headers without crashinggo test ./...passes